"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var uploadgroup_service_1 = require("./uploadgroup.service");
var UploadGroupComponent = /** @class */ (function () {
    function UploadGroupComponent(_message) {
        this._message = _message;
        // @Input() piclist=[];//图片列表
        this.piclist = []; //图片列表
        this.length = 4; //总共长度
        this.size = 500; //文件大小 500K
        this.uploadname = "上传图片";
        this.fileList = [];
        this.edit = false;
        this.piclistChange = new core_1.EventEmitter();
        this.fileListChange = new core_1.EventEmitter();
        this.picDeleteChange = new core_1.EventEmitter();
        this.deletefun = new core_1.EventEmitter();
        this.addfun = new core_1.EventEmitter();
        this.index = null;
        this.count = 0;
    }
    UploadGroupComponent.prototype.uploadclick = function (i) {
        ++this.count;
        if (this.count == 1) {
            this.index = i;
            this.upload.nativeElement.click();
            this.count = 0;
        }
    };
    UploadGroupComponent.prototype.delete = function (index, where) {
        this.piclist[index]['src'] = '';
        this.fileList[index] = 'pic';
        this.fileListChange.emit(this.fileList);
        this.piclistChange.emit(this.piclist);
        if (where) {
            this.picDeleteChange.emit(where);
        }
        this.deletefun.emit();
    };
    UploadGroupComponent.prototype.addImage = function (e) {
        var _this = this;
        var target = e.target;
        var file = target.files[0];
        if (!file) {
            return false;
        }
        var size = file.size;
        var type = file.type;
        var typecheck = new RegExp(/image/i);
        if (!typecheck.test(type)) {
            this._message.create('error', '请上传图片格式');
            return false;
        }
        if (size > 1024 * this.size) {
            this._message.create('error', '最大可上传' + this.size + 'KB的图片');
            return false;
        }
        var reader = new FileReader();
        reader.readAsDataURL(file);
        //var uploadlist=this.uploadlist;
        reader.onload = function (e) {
            // this.piclist.push({src: reader.result});
            // this.piclist[i].push({src: reader.result});
            _this.piclist[_this.index]['src'] = reader.result;
        };
        this.fileList[this.index] = file;
        this.fileListChange.emit(this.fileList);
        this.addfun.emit();
    };
    UploadGroupComponent.prototype.ngOnInit = function () {
    };
    __decorate([
        core_1.Input()
    ], UploadGroupComponent.prototype, "piclist", void 0);
    __decorate([
        core_1.Input()
    ], UploadGroupComponent.prototype, "length", void 0);
    __decorate([
        core_1.Input()
    ], UploadGroupComponent.prototype, "size", void 0);
    __decorate([
        core_1.Input()
    ], UploadGroupComponent.prototype, "uploadname", void 0);
    __decorate([
        core_1.Input()
    ], UploadGroupComponent.prototype, "fileList", void 0);
    __decorate([
        core_1.Input()
    ], UploadGroupComponent.prototype, "edit", void 0);
    __decorate([
        core_1.Output()
    ], UploadGroupComponent.prototype, "piclistChange", void 0);
    __decorate([
        core_1.Output()
    ], UploadGroupComponent.prototype, "fileListChange", void 0);
    __decorate([
        core_1.Output()
    ], UploadGroupComponent.prototype, "picDeleteChange", void 0);
    __decorate([
        core_1.Output()
    ], UploadGroupComponent.prototype, "deletefun", void 0);
    __decorate([
        core_1.Output()
    ], UploadGroupComponent.prototype, "addfun", void 0);
    __decorate([
        core_1.ViewChild('upload')
    ], UploadGroupComponent.prototype, "upload", void 0);
    __decorate([
        core_1.Input()
    ], UploadGroupComponent.prototype, "readonly", void 0);
    UploadGroupComponent = __decorate([
        core_1.Component({
            selector: 'uploadgroup',
            templateUrl: './uploadgroup.component.html',
            styleUrls: ['./uploadgroup.component.scss'],
            providers: [uploadgroup_service_1.UploadGroupService]
        })
    ], UploadGroupComponent);
    return UploadGroupComponent;
}());
exports.UploadGroupComponent = UploadGroupComponent;
